# Maintainer: Daurnimator <daurnimator@archlinux.org>
# Maintainer: Sven-Hendrik Haase <svenstaro@archlinux.org>

# Careful when upgrading this package! It usually breaks ABI without bumping
# soname. Also, be very mindful of the version of spirv-tools that this links
# to. Upstream actually expects the use of the particular commits of
# spirv-tools and spirv-headers that are provided in known_good.json. However,
# if we went that route, we'd have to vendor the resulting spirv-tools libs
# from this glslang build and they would be incompatible with system libs,
# resulting in us having to ship both. Instead, I recommend just waiting until
# upstream releases a compatible version of spirv-tools, then updating the
# spriv-tools system package and only then building glslang against that.
pkgname=glslang
pkgver=13.1.1
pkgrel=2
pkgdesc='OpenGL and OpenGL ES shader front end and validator'
arch=('loong64' 'x86_64')
url='https://github.com/KhronosGroup/glslang'
license=('BSD')
depends=('gcc-libs' 'spirv-tools')
makedepends=('cmake' 'ninja' 'spirv-headers' 'python')
options=('staticlibs')
source=(${pkgname}-${pkgver}.tar.gz::https://github.com/KhronosGroup/glslang/archive/${pkgver}.tar.gz)
sha256sums=('1c4d0a5a38c8aaf89a2d7e6093be734320599f5a6775b2726beeb05b0c054e66')


build() {
  cd ${pkgname}-${pkgver}

  # we need fat LTO objects to not break consumers during linking
  CXXFLAGS+=" -ffat-lto-objects"
  cmake \
    -Bbuild-shared \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_BUILD_TYPE=None \
    -DALLOW_EXTERNAL_SPIRV_TOOLS=ON \
    -DBUILD_SHARED_LIBS=ON
  ninja -Cbuild-shared
  cmake \
    -Bbuild-static \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_BUILD_TYPE=None \
    -DALLOW_EXTERNAL_SPIRV_TOOLS=ON \
    -DBUILD_SHARED_LIBS=OFF
  ninja -Cbuild-static
}

check() {
  cd ${pkgname}-${pkgver}
  ninja -Cbuild-shared test
}

package() {
  cd ${pkgname}-${pkgver}
  DESTDIR="${pkgdir}" ninja -C build-shared install
  DESTDIR="${pkgdir}" ninja -C build-static install

  install -Dm644 LICENSE.txt "${pkgdir}"/usr/share/licenses/${pkgname}/LICENSE

  cd "${pkgdir}"/usr/lib
  for lib in *.so; do
    ln -sf "${lib}" "${lib}.0"
  done
}

# vim: ts=2 sw=2 et:
